<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>遍历对象</title>
</head>

<body>
  <script>
    // 遍历对象
    let obj = {
      sex: '女',
      age: 4,
      uname: '佩奇',
      weight: 12.6,
      hright: 10
    }

    for (let key in obj) {
      console.log(key, '属性名')  //输出的是字符串的'name'  'age'
      console.log(obj[key], '属性值')
      // console.log(obj.key)   //返回一个unfefined
    }
    console.log('----------')
    for (let uname in obj) {
      console.log(obj[uname])
    }

    let arr = [2, 4, 3, 7, 9, 1, 4]
    for (let key in arr) {
      // for..in可以用于遍历数组
      console.log(key)
      console.log(arr[key])
    console.log(arr)
    }



  </script>
</body>

</html>